  <meta charset="utf-8">
<?php
	
	$db=new db;
	$db->connect();
	$db->query("select name,id,theloai from anime where gtheloai=0 order by id asc limit 0,200");
	$data=$db->fetchAll();
	/*echo "<pre>";
	print_r($data);	
	echo "</pre>";*/
	$j=1;
	foreach($data as $row){
		
		
		$vl=strpos($row['theloai'],",");
		
		if($vl===false){
			//Echo ra xem anime nao con bi loi, se fix lai the loai = cach them dau '
			$str=anime_theloai2($row['theloai']);
			$db->query("update anime set theloai='".$str."' where id=".$row['id']);
		}else{
			$arr=explode(",",$row['theloai']);
			foreach($arr as $r2){
			
				$db->query("select id from anime_theloai where name='".trim($r2)."'");
				if($db->num_rows()>0){
					$r3=$db->fetchOne();
					$db->query("select id from anime_theloai_fk where anime_id=".$row['id']." and theloai_id=".$r3['id']);
					if($db->num_rows()>0){
						
					}else{
					$db->nonquery("insert into anime_theloai_fk(anime_id,theloai_id) values(".$row['id'].",".$r3['id'].")");
					}
				}
				
				$db->nonquery("update anime set gtheloai=1 where id=".$row['id']);
			}
		}
		
		if(count($arr)>0){
			//echo $row['theloai']."<Br/>";
		}
		
	}
	
	exit();

?>
			
			
